package com.agileai.pm.module.proc.service;

import java.util.List;

import com.agileai.domain.DataParam;
import com.agileai.domain.DataRow;
import com.agileai.hotweb.bizmoduler.core.StandardServiceImpl;
import com.agileai.pm.cxmodule.ProcWeeklyManage;

public class ProcWeeklyManageImpl
        extends StandardServiceImpl
        implements ProcWeeklyManage {
    public ProcWeeklyManageImpl() {
        super();
    }

	@Override
	public List<DataRow> findDetailedRecords(DataParam detailedTypeParam) {
		String statementId = sqlNameSpace+"."+"findDetailedRecords";
		List<DataRow> result = this.daoHelper.queryRecords(statementId, detailedTypeParam);
		return result;
	}

	@Override
	public void updateEmailTheme(String weeklyId, String emailTheme) {
		String statementId = sqlNameSpace+"."+"updateEmailTheme";
		DataParam param = new DataParam();
		param.put("PWI_ID", weeklyId);
		param.put("PWI_EMAILL_THEME", emailTheme);
		this.daoHelper.updateRecord(statementId, param);
		
	}

	@Override
	public void updateDetailedExplain(String weeklyDetailedId,String weeklyDetailedExplain) {
		String statementId = sqlNameSpace+"."+"updateDetailedExplain";
		DataParam param = new DataParam();
		param.put("PWD_ID", weeklyDetailedId);
		param.put("PWD_EXPLAIN", weeklyDetailedExplain);
		this.daoHelper.updateRecord(statementId, param);
		
	}

	@Override
	public String getTrackId(String weeklyId) {
		String result = "";
		String statementId = sqlNameSpace+"."+"getTrackId";
		DataParam param = new DataParam();
		param.put("PWI_ID", weeklyId);
		DataRow rowResult = new DataRow();
		rowResult = this.daoHelper.getRecord(statementId, param);
		if (rowResult != null && rowResult.size() > 0){
			result = rowResult.stringValue("PPT_ID");
		}
		return result;
	}

	@Override
	public void delTrackInfo(String trackId) {
		String trackStatementId = sqlNameSpace+"."+"delTrackInfo";
		String detailedStatementId = sqlNameSpace+"."+"delTrackDetailedInfo";
		DataParam param = new DataParam();
		param.put("PPT_ID", trackId);
		this.daoHelper.deleteRecords(trackStatementId, param);
		this.daoHelper.deleteRecords(detailedStatementId, param);
	}

	@Override
	public float getThisWeekDayNum(String weeklyId) {
		float result = 0;
		String statementId = sqlNameSpace+"."+"getThisWeekDayNum";
		DataParam param = new DataParam();
		param.put("PWI_ID", weeklyId);
		DataRow rowResult = new DataRow();
		rowResult = this.daoHelper.getRecord(statementId, param);
		if (rowResult != null && rowResult.size() > 0){
			result =Float.parseFloat(rowResult.stringValue("NUM"));
		}
		
		return result;
	}

	@Override
	public float getSurplusDayNum(String planId) {
		float result = (float) 1.11;
		String statementId = sqlNameSpace+"."+"getSurplusDayNum";
		DataParam param = new DataParam();
		param.put("PPA_ID", planId);
		DataRow rowResult = new DataRow();
		rowResult = this.daoHelper.getRecord(statementId, param);
		if (rowResult != null && rowResult.size() > 0){
			result =Float.parseFloat(rowResult.stringValue("NUM"));
			
			String projectTrackId = rowResult.stringValue("PPT_ID");
			DataParam projectTrackParam = new DataParam("PPT_ID",projectTrackId,"PPT_STATE","TRACK_SUMBIT");
			statementId = sqlNameSpace+"."+"updateTrackState";
			this.daoHelper.updateRecord(statementId, projectTrackParam);
		}
		return result;
	}

	@Override
	public float getSumDayNum(String projectId) {
		float result = (float) 1.11;
		String statementId = sqlNameSpace+"."+"getSumDayNum";
		DataParam param = new DataParam();
		param.put("PI_ID", projectId);
		DataRow rowResult = new DataRow();
		rowResult = this.daoHelper.getRecord(statementId, param);
		if (rowResult != null && rowResult.size() > 0){
			result =Float.parseFloat(rowResult.stringValue("NUM"));
		}
		return result;
	}

	@Override
	public void createTrackRecord(DataParam trackParam) {
		String statementId = sqlNameSpace+"."+"createTrackRecord";
		this.daoHelper.insertRecord(statementId, trackParam);
	}

	@Override
	public void createTrackDetailedRecords(List<DataParam> thisWeeklyParamList) {
		String statementId = sqlNameSpace+"."+"createTrackDetailedRecords";
		this.daoHelper.batchInsert(statementId, thisWeeklyParamList);
	}

	@Override
	public int getLimitNum(String userId) {
		int result = 5;
		String statementId = sqlNameSpace+"."+"getLimitNum";
		DataParam param = new DataParam();
		param.put("USER_ID", userId);
		DataRow row =new DataRow();
		row = this.daoHelper.getRecord(statementId, param);
		if(row != null && row.size() > 0){
			result =Integer.parseInt(row.stringValue("USER_WEEKLY_SHOWNUM")) ;
		}
		return result;
	}

	@Override
	public void updateLimitNum(String userId,int limitNum) {
		String statementId = sqlNameSpace+"."+"updateLimitNum";
		DataParam param = new DataParam();
		param.put("USER_ID", userId);
		param.put("USER_WEEKLY_SHOWNUM", limitNum);
		this.daoHelper.updateRecord(statementId, param);
	}

	@Override
	public List<DataRow> findPlanreRecords(DataParam conditionsParam) {
		String statementId = sqlNameSpace+"."+"findPlanreRecords";
		List<DataRow> result = this.daoHelper.queryRecords(statementId, conditionsParam);
		return result;
	}

	@Override
	public void insertWeeklyDetailed(List<DataParam> saveDataList) {
		String statementId = sqlNameSpace+"."+"insertWeeklyDetailed";
		this.daoHelper.batchInsert(statementId, saveDataList);
	}

	@Override
	public void deletWeeklyRecord(String weeklyId) {
		String weeklyStatementId = sqlNameSpace+"."+"deletWeeklyRecord";
		String detailedStatementId = sqlNameSpace+"."+"deletWeeklyDetailedRecord";
		DataParam param = new DataParam();
		param.put("PWI_ID", weeklyId);
		this.daoHelper.deleteRecords(weeklyStatementId, param);
		this.daoHelper.deleteRecords(detailedStatementId, param);
		
	}

	@Override
	public String getOutboxInfo(String userId) {
		String result = "";
		String statementId = sqlNameSpace+"."+"getOutboxInfo";
		DataParam param = new DataParam();
		param.put("userId", userId);
		DataRow rowResult = new DataRow();
		rowResult = this.daoHelper.getRecord(statementId, param);
		if (rowResult != null && rowResult.size() > 0){
			result = rowResult.stringValue("USER_MAIL");
		}
		return result;
	}

	@Override
	public String getEmailInfo(String projectId) {
		String result = "";
		String statementId = sqlNameSpace+"."+"getEmailInfo";
		DataParam param = new DataParam();
		param.put("projectId", projectId);
		DataRow rowResult = new DataRow();
		rowResult = this.daoHelper.getRecord(statementId, param);
		if (rowResult != null && rowResult.size() > 0){
			result = rowResult.stringValue("PI_MAIL_CONFIGURE");
		}
		return result;
	}

	@Override
	public DataRow getInboxInfo(String projectId) {
		DataRow result = new DataRow();
		String statementId = sqlNameSpace+"."+"getInboxInfo";
		DataParam param = new DataParam();
		param.put("projectId", projectId);
		DataRow rowResult = new DataRow();
		rowResult = this.daoHelper.getRecord(statementId, param);
		if (rowResult != null && rowResult.size() > 0){
			result = rowResult;
		}
		return result;
	}

	@Override
	public void updateWeeklyState(String weeklyId, String weeklyState) {
		String statementId = sqlNameSpace+"."+"updateWeeklyState";
		DataParam param = new DataParam();
		param.put("PWI_ID", weeklyId);
		param.put("PWI_STATE", weeklyState);
		this.daoHelper.updateRecord(statementId, param);
		
	}
	
	public List<DataRow> findWeeklyListRecords(String projectId,int startNum,int displayNum) {
		DataParam param = new DataParam("projectId",projectId,"startNum",startNum,"displayNum",displayNum);
		String statementId = sqlNameSpace+"."+"findWeeklyListRecords";
		List<DataRow> result = this.daoHelper.queryRecords(statementId, param);
		return result;
	}
}
